package com.mht.book.operation.impl;

import com.mht.book.entity.book.Book;
import com.mht.book.entity.book.BookList;
import com.mht.book.operation.Operations;

import java.util.Objects;
import java.util.Scanner;

/**
 * @author wangfusheng
 * @version 1.0.0
 * @ClassName BorrowOperation.java
 * @Description 借阅图书
 * @createTime 2022/12/410:56
 */
public class BorrowOperation implements Operations {
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书！");
        System.out.println("请输入您要借阅的图书名称：");
        Scanner sc = new Scanner(System.in);
        String inputName = sc.nextLine();
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            Book book = bookList.getBooks()[i];
            if(Objects.equals(inputName,book.getName())){
                if(false == book.getIsBorrowed()){
                    System.out.println("恭喜你，图书借阅成功，请按时归还图书！");
                    book.setIsBorrowed(true);
                }else {
                    System.out.println("对不起，您要借阅的图书已被别人借走！");
                }
                System.out.println();
                return;
            }
        }
        System.out.println("对不起，我们书架中没有这本书！");
        System.out.println();
    }


//    public static void main(String[] args) {
//        BorrowOperation b = new BorrowOperation();
//        b.work(new BookList());
//    }
}
